package command;

import parser.ChessContentHandlerConstants;
import parser.ParserConstants;
import chess.GhostPiece;
import chess.Tile;

public class KnightsTourMoveCommand extends MoveCommand {

	public KnightsTourMoveCommand(Tile orig, Tile dest) {
		super(orig, dest);
	}

	public void execute(){
		super.execute();
		this.getOrigTile().setPieceHere(new GhostPiece(this.getDestTile().getPieceHere().getPlayer(),this.getOrigTile()));  //Add GhostPiece to old tile
	}
	public void undo(){
		this.getOrigTile().setPieceHere(null);  //Get rid of the ghost piece
		super.undo();
	}
	/**
	 * This method will return a string representation of the command used for importing and
	 * exporting
	 * @return Returns a string representing the object
	 */
	public String exportCode(){
		return "Knight:"+getOrigTile().toString()+"to"+getOrigTile().toString() + "with" + this.secondaryCommand.exportCode();
	}
	/**
	 * This method will return a string representation of the command used for saving and
	 * loading
	 * @return Returns a string representing the object
	 */
	@Override
	public String xmlCode() {
		String code = "<" + ParserConstants.ELEMENT_KNIGHT_MOVE + ">\n";
		
		code += "\t" + getOrigTile().XMLPointTag(ChessContentHandlerConstants.POINT_1).replaceAll("\n","\n\t");
		code += "\n";
		code += "\t" + getDestTile().XMLPointTag(ChessContentHandlerConstants.POINT_2).replaceAll("\n","\n\t");
		code += "\n";
		code += "</" + ParserConstants.ELEMENT_KNIGHT_MOVE + ">\n";
		code += secondaryCommand.xmlCode();
		return code;
	}
	@Override
	public Command getSecondaryCommand() {
		return secondaryCommand;
	}
}
